/**
 * 克隆一份数组
 */
Array.prototype.clone = function() {
  var newArr = [];
  for (var i = 0, len = this.length; i < len; i++) {
    var cur = this[i];
    newArr.push(cur);
  }
  return newArr;
}
/**
 * 冒泡排序，不改变原来的数组
 */
Array.prototype.bubbleSort = function(callback) {
  var newArr = this.clone(),
    flag,
    temp;
  // 比较趟数
  for (var i = 0; i < newArr.length - 1; i++) {
    var curi = newArr[i];
    flag = true; //假设已经排序好
    // 两两比较次数
    for (var j = 0; j < newArr.length - 1 - i; j++) {
      if (callback(newArr[j], newArr[j + 1]) > 0) {
        temp = newArr[j];
        newArr[j] = newArr[j + 1];
        newArr[j + 1] = temp;
        flag = false;
      }
    }
    if(flag) {
      return newArr;
    }
  }
}
